package main

import "fmt"

// 通道的关闭
// https://gobyexample-cn.github.io/closing-channels

func main() {
	jobs := make(chan int, 5)
	done := make(chan bool)

	go func() {
		for {
			j, more := <-jobs
			if more {
				fmt.Println("收到任务", j)
			} else {
				fmt.Println("收到全部任务")
				done <- true
				return
			}
		}
	}()

	for j := 1; j <= 3; j++ {
		jobs <- j
		fmt.Println("发送任务", j)
	}
	close(jobs)
	fmt.Println("发送完所有任务")

	<-done
}
